package 二叉树的所有路径;

import tree_node.TreeNode;

import java.util.ArrayList;
import java.util.List;

class Solution {
    List<String> ret;
    public List<String> binaryTreePaths(TreeNode root) {
        ret = new ArrayList<>();
        dfs(root, new StringBuffer(""));
        return ret;
    }

    void dfs(TreeNode root, StringBuffer _path){
        StringBuffer path = new StringBuffer(_path);
        path.append(root.val);
        if(root.left == null && root.right == null){
            ret.add(path.toString());
            return;
        }
        path.append("->");
        if (root.left != null){
            dfs(root.left, path);
        }
        if (root.right != null){
            dfs(root.right, path);
        }
    }
}